home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 4
/
Apprentice-Release4.iso
/
Source Code
/
C
/
Frameworks
/
Grant's CGI Framework 1.0b12
/
Apple Events
/
AEFunc.c
next >
Wrap
Text File
|
1995-12-09
|
5KB
|
216 lines
/*****
*
* AEFunc.c
*
* This is a support file for "Grant's CGI Framework".
* Please see the license agreement that accompanies the distribution package
* for licensing details.
*
* Copyright ©1995 by Grant Neufeld
* grant@acm.com
* http://arpp1.carleton.ca/grant/
*
*****/
#include "MyConfiguration.h"
#include <stdlib.h>
#include "compiler_stuff.h"
#include "globals.h"
#include "DebugUtil.h"
#include "EventUtil.h"
#include "ErrorUtil.h"
#include "MemoryUtil.h"
#include "AEFunc.h"
/*** FUNCTIONS ***/
/* IM:IAC 4-35 */
OSErr
MyGotRequiredParams ( AppleEvent *theAppleEvent )
{
OSErr theErr;
DescType returnedType;
Size actualSize;
theErr = AEGetAttributePtr ( theAppleEvent, keyMissedKeywordAttr, typeWildCard,
&returnedType, nil, nil, &actualSize );
if ( theErr == errAEDescNotFound )
{
/* all required parameters were retrieved */
return noErr;
}
else if ( theErr == noErr )
{
/* required parameter was missed */
return errAEParamMissed;
}
else
{
return theErr;
}
} /* MyGotRequiredParams */
/* IM:IAC 5-23 */
pascal Boolean
MyAEIdleFunc ( const EventRecord *theEvent, long *sleepTime, RgnHandle *mouseRgn )
{
Boolean theResult = false;
switch ( theEvent->what )
{
#if kCompileWithForeground
case updateEvt :
case activateEvt :
break;
case osEvt :
/* MyAdjustCursor ( theEvent->where, theMouseRgn ); */
doOsEvt ( theEvent );
break;
#endif /* kCompileWithForeground */
case nullEvent :
/* *mouseRgn = theMouseRgn; */
*sleepTime = gSleepTicks; /* may need to change to use correct value for app */
/* I'm not 100% certain that this should be here... */
#if kCompileWithThreadsOptional
if ( gHasThreadMgr )
#endif
{
YieldToAnyThread ();
}
break;
}
return theResult;
} /* MyAEIdleFunc */
#pragma mark -
/* get a string from a parameter */
OSErr
AEGetParamString ( const AppleEvent *theAppleEvent, AEKeyword theAEKeyword, char **theString, char *tempBuffer, long bufferSize )
{
OSErr theErr;
DescType actualType;
Size actualSize;
my_assert ( theString != nil, "\pAEGetParamString: theString ptr is nil" );
my_assert ( *theString == nil, "\pAEGetParamString: string with existing chars received" );
my_assert ( theAppleEvent != nil, "\pAEGetParamString: theAppleEvent ptr is nil" );
my_assert ( tempBuffer != nil, "\pAEGetParamString: tempBuffer ptr is nil" );
theErr = AEGetParamPtr ( theAppleEvent, theAEKeyword, typeChar,
&actualType, (Ptr)tempBuffer, bufferSize, &actualSize );
if ( theErr == noErr )
{
my_assert ( actualSize <= bufferSize, "\pAEGetParamString: actual param size too big" );
/* if the parameter was present, allocate space to copy it into destination string */
*theString = (char *) MyNewPtr ( actualSize + 1, &theErr );
if ( *theString != nil )
{
/* copy the tempBuffer into the destination string */
BlockMove ( tempBuffer, *theString, actualSize );
/* put a null terminator at the end of the string */
(*theString)[actualSize] = nil;
}
}
return theErr;
} /* AEGetParamString */
/* copy a parameter into an existing string block */
OSErr
AEGetParamStringNoAlloc (
const AppleEvent * theAppleEvent,
AEKeyword theAEKeyword,
char * theString,
long stringSize )
{
OSErr theErr;
DescType actualType;
Size actualSize;
my_assert ( theString != nil, "\pAEGetParamString: theString ptr is nil" );
my_assert ( theAppleEvent != nil, "\pAEGetParamString: theAppleEvent ptr is nil" );
my_assert ( stringSize != nil, "\pAEGetParamString: stringSize is nil" );
theErr = AEGetParamPtr ( theAppleEvent, theAEKeyword, typeChar,
&actualType, (Ptr)theString, stringSize, &actualSize );
return theErr;
} /* AEGetParamString */
#pragma segment AppleEvent
/* get a short from a parameter */
OSErr
AEGetParamShort ( const AppleEvent *theAppleEvent, AEKeyword theAEKeyword, short *theShort, char *tempBuffer, long bufferSize )
{
OSErr theErr;
DescType actualType;
Size actualSize;
my_assert ( theShort != nil, "\pAEGetParamShort: theShort ptr is nil" );
my_assert ( theAppleEvent != nil, "\pAEGetParamShort: theAppleEvent ptr is nil" );
my_assert ( tempBuffer != nil, "\pAEGetParamShort: tempBuffer ptr is nil" );
theErr = AEGetParamPtr
( theAppleEvent, theAEKeyword, typeChar, &actualType, (Ptr)tempBuffer, bufferSize, &actualSize );
if ( theErr == noErr )
{
my_assert ( actualSize <= bufferSize, "\pAEGetParamShort: actual param size too big" );
/* terminate the buffer with a null byte so it will be a proper C string */
tempBuffer[actualSize] = nil;
*theShort = atoi ( tempBuffer );
}
return theErr;
} /* AEGetParamShort */
/* get a long value from a parameter */
OSErr
AEGetParamLong ( const AppleEvent *theAppleEvent, AEKeyword theAEKeyword, long *theLong )
{
OSErr theErr;
DescType actualType;
Size actualSize;
my_assert ( theLong != nil, "\pAEGetParamShort: theLong ptr is nil" );
my_assert ( theAppleEvent != nil, "\pAEGetParamShort: theAppleEvent ptr is nil" );
theErr = AEGetParamPtr
( theAppleEvent, theAEKeyword, typeLongInteger, &actualType, (Ptr)theLong, sizeof(long), &actualSize );
if ( theErr == noErr )
{
my_assert ( actualSize <= sizeof(long), "\pAEGetParamLong: actual param size too big" );
}
return theErr;
} /* AEGetParamShort */
/***** EOF *****/